package com.yc.demo.online;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/online.s")
public class OnlineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		// 输出在线的用户
		ServletContext application = request.getServletContext();
		Set<String> loginedUserNames = (Set<String>) 
				application.getAttribute("loginedUserNames");
		PrintWriter out = response.getWriter();
		out.append("当前在线的人：<ol>");
		for(String name :loginedUserNames) {
			out.append("<li>").append(name).append("</li>");
		}
		out.append("</ol>");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
		
	}

}
